/**
 * 文章信息
 */
let mongoose = require('../mongodb.js'), Schema = mongoose.Schema;
import mongoosePaginate from 'mongoose-paginate';
import autoIncrement from 'mongoose-auto-increment';

let ArticleSchema = new Schema({
	// 文章标题
	title: { type: String, required: true },

	// 关键字
	keyword: { type: String, required: false },

	// 描述
	description: { type: String, required: false },

	// 标签
	// tag: { type: Schema.Types.ObjectId, ref: 'Tags' },
	tag: [{ type: Schema.Types.ObjectId, ref: 'Tags' }],

	// 内容
	content: { type: String, required: true },

	// 状态 1 发布 2 草稿
	state: { type: Number, default: 1 },

	// 文章公开状态 1 公开 2 私密
	publish: { type: Number, default: 1 },

	// 缩略图
	thumb: String,

	// 文章分类   1,代码   2,生活   3，路上
	type: { type: Number, required: true, default: 1 },

	// 文章来源
	source: { type: Number, required: true, default: 1 },

	// 发布日期
	create_at: { type: Date, default: Date.now },

	// 最后修改日期
	update_at: { type: Date, default: Date.now },

	// 浏览量
	views: { type: Number, default: 0 },

	//被赞量
	likes: { type: Number, default: 0 },

	//评论数量
	comments: { type: Number, default: 0 }

});

ArticleSchema.set('toObject', { getters: true });

// 翻页 + 自增ID插件配置
ArticleSchema.plugin(mongoosePaginate);

ArticleSchema.plugin(autoIncrement.plugin, {
	model: 'Articles',
	field: 'id',
	startAt: 1,
	incrementBy: 1
});


module.exports = mongoose.model('Articles', ArticleSchema);